package de.pyranja.storage.exception;

import com.google.common.base.Preconditions;

/**
 * Base class for BinaryStorage exceptions.
 * @author Chris Borckholder
 */
public class BinaryStorageException extends RuntimeException {

	private static final long serialVersionUID = 4879655030635687468L;

	// fixed id, used to be in case one can't determine a proper one
	public static final String UNKNOWN = "UNKNOWN";
	
	private final String reference;

	public BinaryStorageException(final String message, final String reference, 
			final Throwable cause) {
		super(message, cause);
		this.reference = Preconditions.checkNotNull(reference,"Cannot construct with null reference");
	}
	
	public BinaryStorageException(final String message, final Throwable cause) {
		this(message, UNKNOWN, cause);
	}

	public BinaryStorageException(final String message, final String reference) {
		this(message, reference, null);
	}

	/**
	 * The identifier of the data that caused the exception
	 * @return the reference
	 */
	public String getReference() {
		return reference;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return super.toString() + "[" + this.reference +"]";
	}	
}
